﻿#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
#include <string>

class MyOutOfRangeException :public exception
{
public:
	MyOutOfRangeException(string errorInfo)
	{
		this->m_ErrorInfo = errorInfo;
	}
	virtual ~MyOutOfRangeException()
	{

	}
	virtual char const* what() const
	{
		//2.返回错误信息；string转char*，.c_str();
		return this->m_ErrorInfo.c_str();
	}

	string m_ErrorInfo;
};
class PersonMyself
{
public:
	PersonMyself(string name, int age)
	{
		this->m_Name = name;
		//1.年龄做检测；
		if (age < 0 || age>200)
		{
			//throw MyOutOfRangeException("我自己的年龄越界异常！");
			throw MyOutOfRangeException(string("我自己的年龄越界异常！"));
		}
	}

	string m_Name;
	int m_Age;
};
void testMyselfException()
{
	try
	{
		PersonMyself("张三", 300);
	}
	catch (MyOutOfRangeException& e)
	{
		cout << e.what() << endl;
	}

}

//main314：编写自己的异常类
int main314()
{
	testMyselfException();//我自己的年龄越界异常！

	system("pause");
	return EXIT_SUCCESS;
}